/**
 * 
 */
package com.gosophia.conferenceManagement.jbpm.test;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import com.gosophia.userManagement.entity.UserInfo;
import com.gosophia.userManagement.service.UserManagementService;

/**
 * 功能：
 * 
 * @author zhangdongsheng
 * @since 2011-3-23 Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
		"classpath:applicationContext-it.xml" })
public class ConferenceJbpmProcessTestBase extends
		AbstractTransactionalJUnit4SpringContextTests {
	private ProcessDefinition processDefinition;
	private ProcessInstance processInstance;
	private JbpmContext jbpmContext;
	@Autowired
	private UserManagementService userManagementService;
	protected UserInfo oneOperator;
	protected UserInfo twoOperator;
	@Autowired
	private JbpmConfiguration jbpmConfiguration;

	@Before
	public void loadingAndDeployProcessingDefiniation() {
		 oneOperator = userManagementService.findUserInfoByUserInfoId(1000L) ;
		  twoOperator = userManagementService.findUserInfoByUserInfoId(1001L) ;
		processDefinition = new ProcessDefinition()
				.parseXmlResource("conference1/processdefinition.xml");
		jbpmContext = jbpmConfiguration.createJbpmContext();
		jbpmContext.deployProcessDefinition(processDefinition);
		processDefinition = jbpmContext.getGraphSession()
				.findLatestProcessDefinition("hygl");
		// processInstance =processDefinition.createProcessInstance();
	}

	@Test
	@Rollback(false)//发布流程时打开
	public void testConferenceProcessStarting() {
		// 加载流程图
		// 测试singal
		// 测试创建job
		// setProcessVariable("conferenceModel",ConferenceConstants.NO_APPLICATION_CONFERENCE);//无需申请
		// setProcessVariable("conferenceType",ConferenceConstants.MIDDLE_TYPE_CONFERENCE);//发起小型会议
		// for (int i = 0; i < 20; i++) {
		// processInstance.signal();
		// }
		// 
	}

	//    
	// private void setProcessVariable(String key, String value){
	// processInstance.getContextInstance().setVariable(key, value);
	// }
	//    
	// @Test
	// public void testNodeActionHandler(){
	// ProcessDefinition conferenceProcessDef =
	// jbpmContext.getGraphSession().findLatestProcessDefinition("huiyi");
	// List<Node> allNodes = conferenceProcessDef.getNodes();
	// for (Node node : allNodes) {
	// logger.debug("输出所有节点的名称："+node.getName());
	// }
	//        
	// }

	@After
	public void tearDown() {
		// jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition);
		jbpmContext.close();
	}

}
